<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*msg.php by StevenY*/
//变量命名出问题，修改整个controller
class Msg extends CI_Controller {
	 
	function __construct()
	{
		parent::__construct();
		if(! $this->session->userdata('login'))
			redirect(site_url('entrance'));
		$this->load->model('mes');
		$this->load->helper('form');
		$this->load->library('form_validation');

		//更新活跃时间
		$this->user->active();

	}
	
	public function index()
	{
		$this->load->view('msg/msg');
	}
	
	//发送信息
	//post 发送
	public function sendmsg()
	{
		//验证是否获得信息
		$rule=array(
				array(
					'field'   => 'to', 
					'label'   => 'to', 
					'rules'   => 'trim|required|is_numeric'
					),
				array(
					'field'   => 'text', 
					'label'   => 'text', 
					'rules'   => 'trim|required'
					),
				array(
					'field'	  => 'title',
					'label'   => 'title',
					'rules'   => 'trim'
					),
			);
			
  		$this->form_validation->set_rules($rule);
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('msg/msg');	
		}
		else
		{
			$to=$this->input->post('to');
			$title=$this->input->post('title');
			$text=$this->input->post('text');
			if ($this->mes->sendto($to,$title,$text))
			{
				echo 0;
			}
			else
			{
				echo $this->mes->get_err_msg();
			}

		}
	}
	
	public function recieve()
	{
		$a['message']=$this->mes->get_msg_list();
		$a['notice']=$this->mes->get_not_list();
		$this->load->view('msg/msg',$a);
	}
	
	//发送通知
	public function sendnot()
	{
	//验证是否获得信息
		$rule=array(
				array(
					'field'   => 'to', 
					'label'   => 'to', 
					'rules'   => 'trim|required|is_natural'
					),
				array(
					'field'   => 'text', 
					'label'   => 'text', 
					'rules'   => 'trim|required'
					),
				array(
					'field'	  => 'title',
					'label'   => 'title',
					'rules'   => 'trim'
					),
			);
			
  		$this->form_validation->set_rules($rule);
		if ($this->form_validation->run() == FALSE)
		{
			echo 'Somthing Wrong';
		}
		else
		{
			$to=$this->input->post('to');
			$title=$this->input->post('title');
			$text=$this->input->post('text');
			if ($this->mes->notice($to,$title,$text))
			{
				echo 0;
			}
			else
			{
				echo $this->mes->get_err_msg();
			}

		}
	}
}

/* End of file msg.php */
/* Location: ./application/controllers/msg.php */